package jt.com.jt809.util;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import jt.com.jt809.bean.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * message 转 字节流
 *
 * @Author OuJiaJun
 * @Date 2024/4/24 14:21
 */
@Slf4j
@Service
public class Message2ByteEncoder {
    public void encode(ChannelHandlerContext ctx, Message msg) throws Exception {
        ByteBuf byteBuf = ctx.alloc().buffer();
        byteBuf.writeBytes(PacketUtil.message2Bytes(msg));
        ctx.write(byteBuf);
    }
}
